<?php
namespace app\index\controller;
use think\Controller;
use xjext\JPush;
use think\DB;
class Index extends Controller
{
    public function index()
    {
    	// sendmsgToDevice('359972069190301','18691988421');
    	// $device_id = '359972069190301';
    	/*$bool = import('xjext.JPush');
    	dump($bool);
		$jpush = new JPush();*/
		/*$extras = array(
                            'title' => '有病人出去了，请注意！',
                            // 'content_type' => 'text',
                            'extras' => array(
                                'key' => 'value'
                            ),
                        );
		$result = JPush::sendToTag(array('1','2','3','4','5','6','7'),'温馨提示：你有病人离开监控范围了！',$extras);*/
		
		$add['device_id'] = '359972069190301';
		$w = array('did'=>$add['device_id']);
		$userid = Model('users_device')->field('uid')->where($w)->select();
		foreach ($userid as $k => $v) {
			$user[] = (string)$v['uid'];
		}
		
		/*$user = array_values($user);*/
		// dump($user);
		unset($userid);
		if(!empty($user)){
			$msg_content = '温馨提示：你有病人离开监控范围了！';
			$extras = array(
	                            'title' => '有病人出去了，请注意！',
	                            // 'content_type' => 'text',
	                            'extras' => array(
	                                'did' => $add['device_id'],
	                                'longitude'=>'122.003792860244',
	                                'latitude'=>'24.997216796875'
	                            )
	                        );
			$result = JPush::sendToTag($user,$msg_content,$extras);
			if( is_object($result)){
				$data = array('info'=>substr(strip_tags($result->xdebug_message),3,150),'time'=>date('Y-m-d H:i:s'));
				Db::name('log')->insert($data);

			}
		}
		

		dump($result);


    }
}
